home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-04-27 | 2.1 KB | 88 lines | [TEXT/MPS ] |
- ;
- ; PatchGlue.a
- ;
- ; Universal patch glue for PatchWorks. MPW Assembler version.
- ;
- ; by Patrick C. Beard.
- ;
- ;
- INCLUDE 'Traps.a'
- INCLUDE 'Patch.a' ; bring in record definitions.
- ;
- FP EQU a3
- ;
- ; void* NewPatchGlue(Patch* this);
- ;
- ; Creates an instance of patch glue. Saves the pointer to the patch object
- ; passed in pc-relative.
- ;
- NewPatchGlue PROC EXPORT
- WITH Patch ; use the Patch object.
- bra.s @measure
- @agent subq #4, sp
- link FP, #0
- movem.l d0-d2/a0-a1/a4, -(sp)
- move.l @patch, a0
- move.l itsOld(a0), 4(FP) ; put old trap address on stack.
- move.b itsState(a0), d0 ; see if patch is on.
- beq.s @restore
- move.l itsBehavior(a0), d0 ; see if a behaviour is there.
- ;; beq.s @restore
-
- clr.l -(sp) ; save room for stack adjustment.
- move.l a0, -(sp) ; pass patch instance.
-
- move.l (a5), a1 ; caller's current port.
- move.l (a1), -(sp)
- move.l a5, -(sp) ; save caller's a5
-
- move.l itsGlobals(a0), GLOBALS ; set up the patch's globals.
- move.l d0, a0
- jsr (a0) ; call the behavior.
-
- move.l (sp), a5 ; restore caller's a5.
-
- add.l #12, sp ; remove stuff we pushed.
- move.l (sp)+, d0
- beq.s @restore
-
- ; we're heading off the patch, return to caller.
- move.l d0, FP
- move.l 32(sp), -(FP) ; get caller's return address.
- move.l 24(sp), -(FP) ; get old value of FP so unlk works.
-
- @restore
- movem.l (sp)+, d0-d2/a0-a1/a4
- unlk FP
- rts
-
- @macsbug
- dc.b $80 + $A, 'PatchAgent' ; macsbug symbol.
-
- @patch
- dc.l 0 ; place to store pointer to instance.
-
- @measure
- lea @patch, a1
- move.l 4(sp), (a1)+ ; store the patch instance pc-relative.
- lea @agent, a0
- sub.l a0, a1 ; compute the size of the glue.
- move.l a1, d1
- move.l d1, d0 ; size of glue in d1.
- _NewPtr ; allocate a block to hold glue.
-
- move.l a0, d0 ; make sure storage allocated properly.
- beq.s @end
-
- move.l a0, a1 ; copy the glue to new block.
- move.l d1, d0
- lea @agent, a0
- _BlockMove
-
- move.l a1, d0 ; return pointer to glue.
- @end
- rts
-
- ENDP
- ;
-